//
//  GYTaskTableViewCell.m
//  LockManagement
//
//  Created by 丁燕春 on 2018/7/28.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

static NSString *taskCellIdentifier = @"taskCellIdentifier";

#import "GYTaskTableViewCell.h"
#import "GYUserInfo.h"

@interface GYTaskTableViewCell()
@property (weak, nonatomic) IBOutlet UILabel *taskTypeLable;
@property (weak, nonatomic) IBOutlet UILabel *autoStateLable;
@property (weak, nonatomic) IBOutlet UILabel *taskExcNameLbale;
@property (weak, nonatomic) IBOutlet UILabel *taskBeginTimeLbale;
@property (weak, nonatomic) IBOutlet UILabel *taskEndTimeLable;
@property (weak, nonatomic) IBOutlet UIButton *taskDownloadBtn;
@property (weak, nonatomic) IBOutlet UILabel *markLable;

@end

@implementation GYTaskTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    GYTaskTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:taskCellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
    }
    
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    //初始化
    [self setBtnAttribute:self.taskDownloadBtn];
}

- (CGFloat)cellHeight {
    return CGRectGetMaxY(self.markLable.frame);
}

- (void)setTaskModel:(GYTask *)taskModel {
    _taskModel = taskModel;
    
    self.taskTypeLable.text = taskModel.taskType == 0 ? @"巡逻" : (taskModel.taskType == 2 ? @"开锁" : @"关锁");
    self.autoStateLable.text = taskModel.taskState == 1 ? @"已授权" : @"等待授权";
    self.taskExcNameLbale.text = taskModel.taskName;
    self.taskBeginTimeLbale.text = taskModel.taskBegin;
    self.taskEndTimeLable.text = taskModel.taskEnd;
    if (taskModel.authName != nil && taskModel.authName.length != 0 && ![taskModel.authName isEqualToString:@""]) {
        //self.taskDownloadBtn.hidden = YES;
        [self.taskDownloadBtn setTitle:@"下载" forState:UIControlStateNormal];
    }else {
        //self.taskDownloadBtn.hidden = NO;
        [self.taskDownloadBtn setTitle:@"授权" forState:UIControlStateNormal];
    }
}

/**
 下载按钮点击事件

 @param sender <#sender description#>
 */
- (IBAction)downloadBtnClick:(UIButton *)sender {
    self.downloadBtnClickCallBack(self.taskModel);
}







/**
 设置按钮属性

 @param btn <#btn description#>
 */
- (void)setBtnAttribute:(UIButton *)btn {
    btn.layer.cornerRadius = 5;
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = BackGroundColor.CGColor;
}

@end
